package com.nimitz.factorEquipment.service.serviceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class OrderNumberGeneratorService {
    private static final String REDIS_KEY_PREFIX = "equipment_";

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    public String generateOrderNumber() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String date = sdf.format(new Date());
//        String key = REDIS_KEY_PREFIX + date;

        Long number = redisTemplate.opsForValue().increment(date);

        // 确保序号是四位数，不足部分用0填充
        String paddedNumber = String.format("%04d", number);
        return REDIS_KEY_PREFIX + date + "_" + paddedNumber;
    }
}
